<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8" />
	<meta name="viewport" content="user-scalable=no" />
	<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
	<meta http-equiv="Pragma" content="no-cache" />
	<meta http-equiv="Expires" content="0" />
	<title>活动主页</title>
	<link rel="stylesheet" type="text/css" href="css/index.css?id=20" />
</head>

<body>
	<div id="mask-kk"></div>
	<div class="header">
		<div class="hd">
			<div class="button" type="button">
				<div class="invite">邀请好友助力</div>
				<div class="battery">超低价换电</div>
			</div>
			<div style="height: 60px;"></div>
		</div>

	</div>
	<div class="middle-box">
		<div class="content-box">
			<div class="button-left">助力进度</div>
			<div class="button-right" style="background: #FDE173">领券记录</div>
		</div>
		<div class="content-img">
		</div>
		<div class="record">
		</div>
	</div>
	<div class="foot">
		<div class="head">
			<div class="get_rule"></div>
			<div class="boot_first"></div>
			<div class="change"></div>
			<div class="boot"></div>
		</div>
		<div class="middle">
			<table class="table1" border="1" cellspacing=0 cellpadding=0>
				<tr valign="middle" align="center"
					style="color: #FFFFFF;background-color: #FE7902; height: 5rem; font-size: 2.5rem;">
					<td style="border-left:#FFFFFF solid 1px; border-right:#FFFFFF solid 1px">电瓶规格</td>
					<td style="border-left:#FFFFFF solid 1px;">原价</td>
					<td style="border-left:#FFFFFF solid 1px">限时特惠价</td>
				</tr>
			</table>
		</div>
		<div class="bottom">
			<div class="process"></div>
			<table class="table" cellspacing=0 cellpadding=0>
				<tr>
					<td class="l" style="border-right:#FE7902 solid 1px; border-bottom:#FE7902 solid 1px;">
						1、参加报名活动，提交活动信息
					<td>
					<td class="r">2、电话回访后，工作人员上门评估电瓶</td>
				</tr>
				<tr>
					<td class="l">3、确认电瓶型号后，用户缴纳活动费用
					<td>
					<td class="r" style="border-top:#FE7902 solid 1px; border-left:#FE7902 solid 1px;">
						4、24小时内，新电池配送及安装并回收旧电瓶
					</td>
				</tr>
			</table>
		</div>
	</div>
	<div id="disappare">
		<img src="img/t.png">
	</div>
</body>
<script src="js/jq.js"></script>
<script src="js/layer.js" type="text/javascript" charset="utf-8"></script>
<script>
	var uid = getUrldata('Uid');
	var hd = getUrldata('hd');
	var type = getUrldata('type');
	var u = navigator.userAgent;
	var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
	var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端	

	//获取活动数据
	$(function () {
		$('html,body').animate({
			scrollTop: 0
		})
		//获取活动信息
		$.ajax({
			type: "POST",
			url: "https://api.cd1a.cn/index.php/activity/swap4/GetIndexData",
			data: {
				userid_locked: uid,
				code_id: hd
			},
			dataType: "json",
			async: true,
			success: function (res) {
				console.log(res)
				if (res.result_code == 200) {
					$('.addr').append(res.address);
					var tr = res.goods_attr;
					var str = '';
					for (var i = 0; i < tr.length; i++) {
						str += '<tr>' +
							'<th>' + tr[i].specifications + '</th>' +
							'<th style="padding:10px;">' + tr[i].price + '<hr />' + '</th>' +
							'<th class="d">' + tr[i].money + '<br/>' + tr[i].seap  + '</th>' +
							'</tr>';
					}
					$('.table1').append(str);
					var ru = res.rule;
					var rule = res.rule1;
					var str2 = '';
					var str1 = '';
					for (var i = 0; i < ru.length; i++) {
						str1 += '<p style="margin-bottom: 3rem;">' + ru[i] + '</p>';
					}
					for (var indx = 0; indx < rule.length; indx++) {
						str2 += '<p style="margin-bottom: 3rem;">' + rule[indx] + '<p>';
					}
					$('.boot').html(str1);
					$('.boot_first').html(str2)
					if (window.performance.navigation.type === 0) {
						if (hd) {
							if (isWeiXin()) {
								help();
							}
						}
					}
					//渲染助力进度
					var sw_list = res.sp_user_list
					if (sw_list.length != 0) {
						var str_sw_list = '';
						for (var i = 0; i < sw_list.length; i++) {
							str_sw_list += '<div class="circle-img" style="background-image: url(' +
								sw_list[i] + ');background-size: cover;"></div>';
						}
						$('.content-img').html(str_sw_list);
					} else {
						var str_sw_list = '';
						for (var i = 0; i < 10; i++) {
							str_sw_list +=
								'<div class="circle-img" style="background-image: url(img/k.png);background-size: cover;"></div>';
						}
						$('.content-img').html(str_sw_list);
					}

					//渲染领券记录
					var card_list = res.card_list
					if (card_list.length != 0) {
						var card_str = '';
						for (var i = 0; i < card_list.length; i++) {
							card_str += '<div class="record-first">' +
								'<div>' + card_list[i].created_at + '</div>' +
								'<div>' + card_list[i].nickname + '</div>' +
								'<div>' + card_list[i].description + '</div>' +
								'</div>';
						}
						$('.record').html(card_str);
					} else {
						$('.record').html(
							"<h1 style='text-align: center;margin-top: 11vh;'>还没有领取记录，赶快参加活动吧</h1>"
						);
					}
				}
			}
		});
	})

	// 选项卡
	$('.button-right').click(function () {
		$('.button-right').css('background', 'white')
		$('.record').show()
		$('.button-left').css('background', '#FDE173')
		$('.content-img').hide()
	})
	$('.button-left').click(function () {
		$('.button-left').css('background', 'white')
		$('.content-img').show()
		$('.button-right').css('background', '#FDE173')
		$('.record').hide()
	})

	//分享页面
	$('.invite').click(function () {
		if (uid == '' || uid == null) {
			if (isWeiXin()) {
				(function () {
					window.alert = function (name) {
						var iframe = document.createElement("IFRAME");
						iframe.style.display = "none";
						iframe.setAttribute("src", 'data:text/plain');
						document.documentElement.appendChild(iframe);
						window.frames[0].window.alert(name);
						iframe.parentNode.removeChild(iframe);
					}
				})();
				alert('没有您的用户信息，请先前往小程序登录');
				return
			}
			if (isiOS) {
				//ios
				window.webkit.messageHandlers.showAlert.postMessage('没有您的用户信息，请先登录');
				return
			}
			if (isAndroid) {
				//Android
				window.TiantianCharge_Android.showAlert('没有您的用户信息，请先登录');
				return
			}
		} else {
			window.location.href = 'share.html?Uid=' + uid
		}

	})

	// 助力
	function help() {
		$.ajax({
			type: 'POST',
			url: 'https://api.cd1a.cn/index.php/activity/power5/Insertpower',
			data: {
				user_id: uid,
				code_id: hd,
				type: type
			},
			success: function (res) {
				console.log(res)
				if (res.code == 1005) {
					$("#disappare").show().delay(3000).hide(300);
					$('#mask-kk').css({
						display: 'block',
						height: $(document).height()
					}).delay(3000).hide(300);
				} else if (res.code == 408) {
					return
				} else {
					if (isWeiXin()) {
						(function () {
							window.alert = function (name) {
								var iframe = document.createElement("IFRAME");
								iframe.style.display = "none";
								iframe.setAttribute("src", 'data:text/plain');
								document.documentElement.appendChild(iframe);
								window.frames[0].window.alert(name);
								iframe.parentNode.removeChild(iframe);
							}
						})();
						alert(res.msg);
						return
					}
					if (isiOS) {
						//ios
						let ios_msg = res.msg
						window.webkit.messageHandlers.showAlert.postMessage(ios_msg);
						return
					}
					if (isAndroid) {
						let android_msg = res.msg
						//Android
						window.TiantianCharge_Android.showAlert(android_msg);
						return
					}
				}

			}
		})
	}


	//开始换电
	$('.battery').click(function () {
		if (uid == '' || uid == null) {
			if (isWeiXin()) {
				(function () {
					window.alert = function (name) {
						var iframe = document.createElement("IFRAME");
						iframe.style.display = "none";
						iframe.setAttribute("src", 'data:text/plain');
						document.documentElement.appendChild(iframe);
						window.frames[0].window.alert(name);
						iframe.parentNode.removeChild(iframe);
					}
				})();
				alert('没有您的用户信息，请先前往小程序登录');
				return
			}
			if (isiOS) {
				//ios
				window.webkit.messageHandlers.showAlert.postMessage('没有您的用户信息，请先登录');
				return
			}
			if (isAndroid) {
				//Android
				window.TiantianCharge_Android.showAlert('没有您的用户信息，请先登录');
				return
			}
		}

		//判断该用户是否参加过活动	
		$.ajax({
			type: "POST",
			url: "https://api.cd1a.cn/index.php/activity/swap4/user_order",
			data: {
				userid_locked: uid
			},
			dataType: "json",
			async: true,
			success: function (res) {
				if (res.result_code == 200) {
					var data = res.data;
					if (data == null) {
						//信息录入
						window.location.href = 'info.html?locked=' + uid + '&types=' + type
					} else {
						if (data.type == 2) {
							if (isWeiXin()) {
								(function () {
									window.alert = function (name) {
										var iframe = document.createElement("IFRAME");
										iframe.style.display = "none";
										iframe.setAttribute("src", 'data:text/plain');
										document.documentElement.appendChild(iframe);
										window.frames[0].window.alert(name);
										iframe.parentNode.removeChild(iframe);
									}
								})();
								alert('退款申请已提交，请您耐心等候！');
								return
							}
							if (isiOS) {
								//ios
								window.webkit.messageHandlers.showAlert.postMessage(
									'退款申请已提交，请您耐心等候！');
								return
							}
							if (isAndroid) {
								//Android
								window.TiantianCharge_Android.showAlert('退款申请已提交，请您耐心等候！');
								return
							}
						}

						//去支付定金
						if (data.course == 1) {
							if(data.city == '太原市'){
								if (isWeiXin()) {
									(function () {
										window.alert = function (name) {
											var iframe = document.createElement("IFRAME");
											iframe.style.display = "none";
											iframe.setAttribute("src", 'data:text/plain');
											document.documentElement.appendChild(iframe);
											window.frames[0].window.alert(name);
											iframe.parentNode.removeChild(iframe);
										}
									})();
									alert('该地区暂无库存，敬请期待');
									return
								}
								if (isiOS) {
									//ios
									window.webkit.messageHandlers.showAlert.postMessage(
										'该地区暂无库存，敬请期待');
									return
								}
								if (isAndroid) {
									//Android
									window.TiantianCharge_Android.showAlert('该地区暂无库存，敬请期待');
									return
								}
							}
							
							window.location.href = 'pay_down.html?locked=' + uid;
							return
						}
						//去支付定金
						if (data.course == 2 && data.price == 0) {
							if(data.city == '太原市'){
							if (isWeiXin()) {
								(function () {
									window.alert = function (name) {
										var iframe = document.createElement("IFRAME");
										iframe.style.display = "none";
										iframe.setAttribute("src", 'data:text/plain');
										document.documentElement.appendChild(iframe);
										window.frames[0].window.alert(name);
										iframe.parentNode.removeChild(iframe);
									}
								})();
								alert('该地区暂无库存，敬请期待');
								return
							}
							if (isiOS) {
								//ios
								window.webkit.messageHandlers.showAlert.postMessage(
									'该地区暂无库存，敬请期待');
								return
							}
							if (isAndroid) {
								//Android
								window.TiantianCharge_Android.showAlert('该地区暂无库存，敬请期待');
								return
							}	
							}
							window.location.href = 'pay_down.html?locked=' + uid;
							return
						}

						if (data.course == 2 && data.attr_id == 0) {
							//跳转
							window.location.href = 'pro_gress.html?id=' + data.battery_id

						}

						if (data.course == 2 && data.attr_id == 0 && data.operator_id == 0) {
							//跳转
							window.location.href = 'pro_gress.html?id=' + data.battery_id

						}
						//去支付尾款
						if (data.attr_id != 0 && data.course == 2) {
							window.location.href = 'payment.html?bid=' + data.battery_id + ':' + uid;
							return
						}

						//支付尾款后
						if (data.course == 3) {
							//跳转
							window.location.href = 'pro_gress.html?id=' + data.battery_id
						}
						//客户端完成	
						if (data.course == 4 || data.course == 5) {
							window.location.href = 'info.html?locked=' + uid + '&types=' + type
						}
					}
				}

			}
		});

	})

	//判断微信
	function isWeiXin() {
		var ua = window.navigator.userAgent.toLowerCase();
		if (ua.match(/MicroMessenger/i) == 'micromessenger') {
			return true; // 是微信端
		} else {
			return false;
		}
	}

	function getUrldata(name) {
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
		var r = window.location.search.substr(1).match(reg);
		if (r != null) return decodeURI(r[2]);
		return null;
	}
</script>

</html>